﻿using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using System.Text;
using TypeMock.ArrangeActAssert;
using Core.Infrastructure.ViewModelBase;
using Microsoft.Practices.Composite.Events;
using CThru.Silverlight;

namespace Core.Infrastructure.Test
{
    public class ViewModelBaseTests
    {
        [Test, SilverlightUnitTest]
        public void RaisePropertyChanged_PropertySelectorPassed_PropertyChangedFired()
        {
            ViewModelBase.ViewModelBase viewModelBase = Isolate.Fake.Instance<ViewModelBase.ViewModelBase>();
            Isolate.WhenCalled(() => viewModelBase.RaisePropertyChanged<IEventAggregator>(null)).CallOriginal();

            bool propertyFired = false;

            viewModelBase.PropertyChanged += (s, e) =>
                {
                    propertyFired = true;
                };

            viewModelBase.RaisePropertyChanged(() => viewModelBase.EventAggregator);

            Assert.True(propertyFired);
        }

        [Test, SilverlightUnitTest]
        public void RaisePropertyChanged_PropertySelectorPassed_PropertyPropertyNameFired()
        {
            ViewModelBase.ViewModelBase viewModelBase = Isolate.Fake.Instance<ViewModelBase.ViewModelBase>();

            string propertyName = null;

            viewModelBase.PropertyChanged += (s, e) =>
            {            
                propertyName = e.PropertyName;
            };

            viewModelBase.RaisePropertyChanged(() => viewModelBase.EventAggregator);

            Assert.AreEqual("EventAggregator", propertyName);
        }
    }
}
